package com.mycompany.app;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.stereotype.Component;
import org.springframework.util.StopWatch;

@Component
public class TracingPostProcessor implements BeanPostProcessor {

	Log log = LogFactory.getLog(this.getClass().getSimpleName());
	StopWatch stopWatch = new StopWatch();
	
	@Override
	public Object postProcessAfterInitialization(Object bean, String beanName)
			throws BeansException {
		stopWatch.stop();
		log.debug("after " + stopWatch.prettyPrint());
		return bean;
	}

	@Override
	public Object postProcessBeforeInitialization(Object bean, String beanName)
			throws BeansException {
		stopWatch.start(beanName);
		log.debug("before " + beanName);
		return bean;
	}



}
